//
//  testaddpic.m
//  testjson
//
//  Created by fcbayern on 2020/12/1.
//  Copyright © 2020 fcbayern. All rights reserved.
//

#import "testaddpic.h"
#import "Masonry.h"
#import "AFNetworking.h"
#import "ALAssetsLibrary+CustomPhotoAlbum.h"
@interface testaddpic ()
@property(strong,nonatomic)UIButton * addpic;
@property(strong,nonatomic)UIImageView * picview;
@property(strong,nonatomic)UIAlertView *myAlertView;

@end

@implementation testaddpic

- (void)viewDidLoad {
    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)];
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    _addpic = [[UIButton alloc]initWithFrame:CGRectMake(200, 200, 100, 100) ];
    _addpic.backgroundColor = [UIColor redColor];
    [self.view addSubview:_addpic];
    UIImage * header = [UIImage imageNamed:@"head"];
    _picview = [[UIImageView alloc]initWithImage:header];
    
     [_addpic addGestureRecognizer:longPress];
    longPress.minimumPressDuration = 1;
               longPress.allowableMovement = 100;
    [self.view addSubview:_picview];
    [_picview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.bottom.equalTo(self.view.mas_bottom).with.offset(-100);
        make.height.equalTo(self.view.mas_width).multipliedBy(0.3);
        make.width.equalTo(self.view.mas_width).multipliedBy(0.5);
    }];
    [_addpic addTarget:self action:@selector(addPicture:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)addPicture:(id)sender{
  
}

- (void)longPressAction:(UILongPressGestureRecognizer *)longPress

{
   
    NSLog(@"1231231111111");
    UIImage * header = [UIImage imageNamed:@"head"];
    
    UIAlertController * alert1 = [UIAlertController alertControllerWithTitle:@"提示" message:@"确定要删除吗?" preferredStyle:UIAlertControllerStyleAlert];
        [self presentViewController:alert1 animated:YES completion:nil];
    UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){
        ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
        [library saveImage:header toAlbum:@"gang" completion:^(NSURL *assetURL, NSError *error) {
            if (!error) {
        
            }
         } failure:^(NSError *error) {
        
         }];
    }];
    UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
               
        }];
    [alert1 addAction:defaultAction];
    [alert1 addAction:cancelAction];
   

}




      

  


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
